package spring.core.examples.xml;

import java.util.LinkedHashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Required;

/**
 * Demonstrates a bean that supports setter based dependency injection. Setter
 * based dependency injection needs a constructor with no arguments an setters
 * to set the attributes. It is the recommended way to create a bean in Spring.<br/>
 * <br/>
 * Also demonstrates how to make attributes mandatory during bean creation in
 * Spring. When using this feature this bean will not be independent from Spring
 * any longer.
 */
public class Person {

	/** The name. */
	String name;

	/** The first name. */
	String firstName;

	/** The age. */
	Integer age;

	/** The childs. */
	Set<Person> childs = new LinkedHashSet<Person>();

	/**
	 * Instantiates a new person.
	 */
	public Person() {
		super();
	}

	/**
	 * Adds the chile.
	 * 
	 * @param child
	 *            the child
	 */
	public void addChild(Person child) {
		this.getChilds().add(child);
	}

	/**
	 * Gets the age.
	 * 
	 * @return the age
	 */
	public Integer getAge() {
		return age;
	}

	/**
	 * Gets the childs.
	 * 
	 * @return the childs
	 */
	public Set<Person> getChilds() {
		return childs;
	}

	/**
	 * Gets the first name.
	 * 
	 * @return the first name
	 */
	@Required
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Gets the full name.
	 * 
	 * @return the full name
	 */
	public String getFullName() {
		return this.getFirstName() + " " + this.getName();
	}

	/**
	 * Gets the name.
	 * 
	 * @return the name
	 */
	@Required
	public String getName() {
		return name;
	}

	/**
	 * Sets the age.
	 * 
	 * @param age
	 *            the new age
	 */
	public void setAge(Integer age) {
		this.age = age;
	}

	/**
	 * Sets the childs.
	 * 
	 * @param childs
	 *            the new childs
	 */
	public void setChilds(Set<Person> childs) {
		this.childs = childs;
	}

	/**
	 * Sets the first name.
	 * 
	 * @param firstName
	 *            the new first name
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * Sets the name.
	 * 
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * To string.
	 * 
	 * @return the string
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return this.getClass().getSimpleName() + " (" + this.getFirstName()
				+ ", " + this.getName() + ", " + this.getAge() + ", "
				+ this.getChilds() + ")";
	}
}
